package com.xiaoyu.lanling.util

import `in`.srain.cube.util.UTUtil
import android.os.Bundle
import androidx.annotation.CheckResult

data class BundleWrapper(val name: String) {
    val bundle: Bundle = Bundle()

    fun put(key: String, value: String) {
        bundle.putString(key, value)
    }

    fun put(key: String, value: Int) {
        bundle.putInt(key, value)
    }

    fun put(key: String, value: Long) {
        bundle.putLong(key, value)
    }

    fun put(key: String, value: Boolean) {
        bundle.putBoolean(key, value)
    }
}

@CheckResult
fun event(eventName: String): BundleWrapper {
    return BundleWrapper(eventName)
}

@CheckResult
fun BundleWrapper.prop(propertyName: String, propertyValue: String): BundleWrapper {
    this.put(propertyName, propertyValue)
    return this
}

@CheckResult
fun BundleWrapper.prop(propertyName: String, propertyValue: Boolean): BundleWrapper {
    this.put(propertyName, propertyValue)
    return this
}

@CheckResult
fun BundleWrapper.prop(key: String, propertyValue: Int): BundleWrapper {
    this.put(key, propertyValue)
    return this
}

@CheckResult
fun BundleWrapper.prop(key: String, propertyValue: Long): BundleWrapper {
    this.put(key, propertyValue)
    return this
}

fun BundleWrapper.logEvent() {
    UTUtil.getInstance().logEvent(this.name, this.bundle)
}